package com.zhu.storesmanager;

import java.util.ArrayList;
import java.util.List;

import com.zhu.storesmanager.models.DataItem;
import com.zhu.storesmanager.models.ModelItem;
import com.zhu.storesmanager.models.ProjectDataItem;
import com.zhu.storesmanager.models.VisitTaskInfo;
import com.zhu.storesmanager.provider.StoresManagerSettings;
import com.zhu.storesmanager.utils.Actions;
import com.zhu.storesmanager.utils.DataUtils;
import com.zhu.storesmanager.utils.DatabaseUtil;
import com.zhu.storesmanager.utils.SalesData;
import com.zhu.storesmanager.utils.ViewsUtil;
import com.zhu.storesmanager.views.ChoiceView;
import com.zhu.storesmanager.views.ChoiceView.DataChangeListener;
import com.zhu.storesmanager.views.DateView;
import com.zhu.storesmanager.views.PhotoView;
import com.zhu.storesmanager.views.PopMenu;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

/**
 * 门店展台信息
 */
public class SvStoreBoothActivity extends Activity implements OnClickListener{

	//异步查询数据库token
	private final static int DATAITEM_QUERY_TOKEN = 0; //查询所有数据词典
	private final static int SAVEDATA_QUERY_TOKEN = 1; //查询数据库保存的数据
	private final static int PROJECT_DATA_QUERY_TOKEN = 2; //拜访文本数据
	private DataQueryHandler mDataQueryHandler = null; //数据异步查询Handler

	private ChoiceView mShapeChoiceView = null; //形状
	private ChoiceView mInfoChoiceView = null; //信息
	private ChoiceView mBadChoiceView = null; //信息
	private ChoiceView mConnectionChoiceView = null; //连线
	private RadioGroup mRadioGroup = null; //是否修好
	private DateView mDateView = null; //损坏日期
	private long mDbID = -1; //数据库ID
	private VisitTaskInfo mVisitTaskInfo = null; //拜访门店数据
	private LinearLayout mLinearLayout = null;
	private PhotoView mAllPhotoView = null; //全景
	private PhotoView mFrontPhotoView = null; //正面
	private PhotoView mTimePhotoView = null; //流光
	private PopMenu mPopMenu = null; //弹出菜单
	private boolean isDataChange = true; //数据是否发生变化
	private List<ProjectDataItem> mProjectList = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Parcelable parcelable = getIntent().getParcelableExtra("info");
        mVisitTaskInfo = (VisitTaskInfo) parcelable;
        setContentView(R.layout.activity_sv_storesbooth);

        setupViews();
        initData();
    }

    /**
     * 初始化界面
     */
    private void setupViews(){
    	((TextView) findViewById(R.id.title_text)).setText(R.string.store_booth);
    	mShapeChoiceView = (ChoiceView)findViewById(R.id.svstorebooth_shape);
    	mInfoChoiceView = (ChoiceView)findViewById(R.id.svstorebooth_info);
    	mBadChoiceView = (ChoiceView)findViewById(R.id.svstorebooth_baditems);
    	mConnectionChoiceView = (ChoiceView)findViewById(R.id.svstorebooth_connection);
    	mDateView = (DateView)findViewById(R.id.svstorebooth_baddate);
    	mDateView.initData(this, DateView.TYPE_DAY, 0);
    	mRadioGroup = (RadioGroup)findViewById(R.id.svstorebooth_radiogroup);
    	findViewById(R.id.svbottom_menu_back).setOnClickListener(this);
    	findViewById(R.id.svbottom_menu_save).setOnClickListener(this);
    	findViewById(R.id.svbottom_menu_menu).setOnClickListener(this);
    	mAllPhotoView = (PhotoView)findViewById(R.id.photo_all);
    	mAllPhotoView.initData(this, R.string.booth_photo_all);
    	mFrontPhotoView = (PhotoView)findViewById(R.id.photo_front);
    	mFrontPhotoView.initData(this, R.string.booth_photo_front);
    	mTimePhotoView = (PhotoView)findViewById(R.id.photo_time);
    	mTimePhotoView.initData(this, R.string.booth_photo_time);
    	mPopMenu = new PopMenu(this, findViewById(R.id.bottom_menu), PopMenu.MENU_BOOTH);
        mPopMenu.setVisitTaskInfo(mVisitTaskInfo);
    }

    /*
     * (non-Javadoc)
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v != null){
			switch(v.getId()){
				case R.id.svbottom_menu_back : //返回
					if(!doBack()){
					    finish();
					}
					break;
				case R.id.svbottom_menu_save: //保存
					saveData();
					break;
				case R.id.svbottom_menu_menu: //菜单
                	mPopMenu.showMenu();
                	break;
			}
		}
	}

	/**
	 * 初始化话数据
	 */
	private void initData(){
		if(!DataUtils.mUserData.isAdmin()){ //检测非管理员
			if(mDataQueryHandler == null){
				mDataQueryHandler = new DataQueryHandler(getContentResolver());	
			}
			startQueryProjects();	
		}else{
			setDataFromAdminSearchData();
		}
	}

	/**
	 * 开始查询数据词典数据
	 */
	private void startQueryDataItemList(){
		if(mDataQueryHandler == null){
			mDataQueryHandler = new DataQueryHandler(getContentResolver());	
		}
		//查询指定类型的型号列表数据
		String where = StoresManagerSettings.DataDictionaryColumns.DATA_TYPE + "=" + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_BADITEMS
				+ " OR " + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE + "=" + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_CONNECTION
		+ " OR " + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE + "=" + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_INFO
		+ " OR " + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE + "=" + StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_SHAPE;

		mDataQueryHandler.startQuery(DATAITEM_QUERY_TOKEN, null, 
				StoresManagerSettings.DataDictionaryColumns.CONTENT_URI_NO_NOTIFICATION,
				null, where, null, null);
	}

	/**
	 * 开始查询数据库保存数据
	 */
	private void startQuerySavedList(){
		//查询指定门店数据
		String where = StoresManagerSettings.SupervisorStoreBoothColumns.STOREID + "=\'" + mVisitTaskInfo.mStoreId +"\'";
		mDataQueryHandler.startQuery(SAVEDATA_QUERY_TOKEN, null, 
				StoresManagerSettings.SupervisorStoreBoothColumns.CONTENT_URI_NO_NOTIFICATION,
				null, where, null, null);
	}

    /**
     * 查询project数据
     */
    private void startQueryProjects(){
    	String where = StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE + "=" + StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH;
    	mDataQueryHandler.startQuery(PROJECT_DATA_QUERY_TOKEN, null, 
				StoresManagerSettings.DataProjectsColumns.CONTENT_URI_NO_NOTIFICATION,
				null, where, null, null);
    }

	/**
	 * 更新选择栏数据词典数据
	 */
	private void updateDataItemFromCursor(Cursor cursor){
		try {
			List<DataItem> shapeList = new ArrayList<DataItem>(); //形状选择数据集
			List<DataItem> infoList = new ArrayList<DataItem>(); //信息选择数据集
			List<DataItem> badItemsList = new ArrayList<DataItem>(); //坏项目选择数据集
			List<DataItem> connectionList = new ArrayList<DataItem>();  //连线选择数据集

            final int dataIDIndex = cursor.getColumnIndexOrThrow(StoresManagerSettings.DataDictionaryColumns._ID);
            final int dataNameIndex = cursor.getColumnIndexOrThrow(StoresManagerSettings.DataDictionaryColumns.DATA_NAME);
            final int dataTypeIndex = cursor.getColumnIndexOrThrow(StoresManagerSettings.DataDictionaryColumns.DATA_TYPE);
            while (cursor.moveToNext()) {//遍历所有型号数据
            	DataItem item = new DataItem();
            	item.mDataId = cursor.getString(dataIDIndex);
            	item.mDataName = cursor.getString(dataNameIndex);
            	item.mDataType = cursor.getInt(dataTypeIndex);
            	if(StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_SHAPE == item.mDataType){
            		shapeList.add(item);
            	}else if(StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_INFO == item.mDataType ){
            		infoList.add(item);
            	}else if(StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_BADITEMS == item.mDataType){
            		badItemsList.add(item);
            	}else if(StoresManagerSettings.DataDictionaryColumns.DATA_TYPE_CONNECTION == item.mDataType){
            		connectionList.add(item);
            	}
            }
            //更新界面数据
            mShapeChoiceView.setChoiceDataList(shapeList);
            mInfoChoiceView.setChoiceDataList(infoList);
            mBadChoiceView.setChoiceDataList(badItemsList);
            mConnectionChoiceView.setChoiceDataList(connectionList);
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("zhu", "updateDataItemFromCursor error");
        } finally {
        	if(cursor != null){
        		cursor.close();
        		cursor = null;
        	}
        }
		startQuerySavedList();
	}

	 /**
     * 更新数据从数据库保存的数据
     * @param cursor 数据
     */
    private void updateSavedDataFromCursor(Cursor cursor){
    	if(cursor != null && cursor.moveToFirst() && cursor.getCount() > 0){
    		boolean isSaved = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SAVED)) == 1 ? true : false;
    		String shape = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_SHAPE));
    		String info = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_INFO));
    		String baditems = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADITEMS));
    		int complete = cursor.getInt(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADCOMPLETE));
    		long date = cursor.getLong(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADDATE));
    		String connection = cursor.getString(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_CONNECTION));
    		mDbID = cursor.getLong(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns._ID));
    		Log.e("zhu", mDbID +" " +shape);
    		//单选数据
    		mShapeChoiceView.setSelectedData(DataUtils.updateStringDataFromHistoryData(mProjectList, shape, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 1));
            mInfoChoiceView.setSelectedData(DataUtils.updateStringDataFromHistoryData(mProjectList, info, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 2));
            mBadChoiceView.setSelectedData(DataUtils.updateStringDataFromHistoryData(mProjectList, baditems, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 3));
            mConnectionChoiceView.setSelectedData(DataUtils.updateStringDataFromHistoryData(mProjectList, connection, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 6));
            complete = DataUtils.updateIntDataFromHistoryData(mProjectList, complete, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 4);
            date = DataUtils.updateLongDataFromHistoryData(mProjectList, date, isSaved, 
    				StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 5);

            byte[] allImage = cursor.getBlob(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOALL));
    		byte[] frontImage = cursor.getBlob(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOFRONT));
    		byte[] timeImage = cursor.getBlob(cursor.getColumnIndexOrThrow(
    				StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOTIME));
            //图片数据
            mAllPhotoView.setImageData(allImage);
            mFrontPhotoView.setImageData(frontImage);
            mTimePhotoView.setImageData(timeImage);
            //设置选中是否
            if(complete != -1){
            	if(complete == 1){
            		mRadioGroup.check(mRadioGroup.getChildAt(0).getId());
            	}else{
            		mRadioGroup.check(mRadioGroup.getChildAt(1).getId());
            	}
            }
            mDateView.setSavedData(date);
    	}else{
    		Bitmap map = null;
    		mAllPhotoView.setImageData(map);
            mFrontPhotoView.setImageData(map);
            mTimePhotoView.setImageData(map);
    	}
    	if(cursor != null){
    		cursor.close();
    		cursor = null;
    	}
    }

	/**
	 * 数据保存
	 */
	private void saveData(){
		ContentValues values = new ContentValues();
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_SHAPE, mShapeChoiceView.getSaveData());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_INFO, mInfoChoiceView.getSaveData());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADITEMS, mBadChoiceView.getSaveData());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_SHAPETEXT, mShapeChoiceView.getText().toString());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_INFOTEXT, mInfoChoiceView.getText().toString());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADITEMSTEXT, mBadChoiceView.getText().toString());
		//获取修复损坏与否
		int complete = -1;
		int selectViewID = mRadioGroup.getCheckedRadioButtonId();
		if(selectViewID != -1){
			selectViewID = mRadioGroup.indexOfChild(mRadioGroup.findViewById(selectViewID));
			if(selectViewID == 0){
				complete = 1;
			}else{
				complete = 0;
			}
		}
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADCOMPLETE, complete);
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_BADDATE, mDateView.getTime());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_CONNECTION, mConnectionChoiceView.getSaveData());
		values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_CONNECTIONTEXT, mConnectionChoiceView.getText().toString());
		values.put(StoresManagerSettings.SAVED, 0);
		//图片数据
		if(mAllPhotoView.isNeedSavedData()){ //全景
			values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOALL, mAllPhotoView.getBitmapData());
			mAllPhotoView.setImageChange(false);
		}
		if(mFrontPhotoView.isNeedSavedData()){ //正面
			values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOFRONT, mFrontPhotoView.getBitmapData());
			mFrontPhotoView.setImageChange(false);
		}
		if(mTimePhotoView.isNeedSavedData()){ //流光
			values.put(StoresManagerSettings.SupervisorStoreBoothColumns.BOOTH_PHOTOTIME, mTimePhotoView.getBitmapData());
			mTimePhotoView.setImageChange(false);
		}
		if(ViewsUtil.checkChoiceViewData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 1), mShapeChoiceView)
				&& ViewsUtil.checkChoiceViewData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 2), mInfoChoiceView)
				&& ViewsUtil.checkChoiceViewData(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 6), mConnectionChoiceView)
				&& checkBadData()){
			DatabaseUtil.saveVisitStatus(this, DatabaseUtil.TYPE_BOOTH , Integer.parseInt(mVisitTaskInfo.mVisitId), 1);
		}else{
			DatabaseUtil.saveVisitStatus(this, DatabaseUtil.TYPE_BOOTH , Integer.parseInt(mVisitTaskInfo.mVisitId), 0);
		}
		if(mDbID == -1){ //不存在则插入
			Log.e("zhu", "insert=" +complete);
			values.put(StoresManagerSettings.SupervisorStoreBoothColumns.STOREID, mVisitTaskInfo.mStoreId);
			Uri uri = getContentResolver().insert(StoresManagerSettings.SupervisorStoreBoothColumns.CONTENT_URI_NO_NOTIFICATION, values);
			mDbID = Long.parseLong(uri.getPathSegments().get(1));
		}else{ //存在则更新数据
			Log.e("zhu", "update=" +complete);
			getContentResolver().update(StoresManagerSettings.SupervisorStoreBoothColumns.getContentUri(mDbID, false), values, null, null);
		}
		Actions.toastShort(this, this.getString(R.string.datasave_success));
	}

	/**
	 * 检测破损项目数据是否填写完整
	 * @return true 填写完成 否则false
	 */
	private boolean checkBadData(){
		if(DataUtils.isProjectDataShow(mProjectList, StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH, 3)){
			return !Actions.isNull(mBadChoiceView.getSaveData());
		}
		return true;
	}
	/**
	 * 创建日期选择dialog
	 * @param id 创建dialogID
	 * (non-Javadoc)
	 * @see android.app.Activity#onCreateDialog(int)
	 */
	protected Dialog onCreateDialog(int id) {
		if(mDateView != null){
			return mDateView.onCreateDialog(id);
		}
		return null;
	}

	/**
	 * 准备dialog数据
	 * (non-Javadoc)
	 * @see android.app.Activity#onPrepareDialog(int, android.app.Dialog)
	 */
	 protected void onPrepareDialog(int id, Dialog dialog) { 
		 if(mDateView != null){
			mDateView.onPrepareDialog(id, dialog);
		 }
	 }

	/**
	 * 异步数据查询
	 */
	private final class DataQueryHandler extends AsyncQueryHandler {
        public DataQueryHandler(ContentResolver contentResolver) {
            super(contentResolver);
        }

        /**
         * 查询结果返回
         * (non-Javadoc)
         * @see android.content.AsyncQueryHandler#onQueryComplete(int, java.lang.Object, android.database.Cursor)
         */
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            switch (token) {
                case DATAITEM_QUERY_TOKEN:
                	updateDataItemFromCursor(cursor);
                    break;
                case SAVEDATA_QUERY_TOKEN:
                	updateSavedDataFromCursor(cursor);
                	break;
                case PROJECT_DATA_QUERY_TOKEN:
               	   updateProjectDataFromCursor(cursor);
                   break;
                default:
                    Log.e("zhu", "onQueryComplete called with unknown token " + token);
            }
        }

        @Override
        protected void onDeleteComplete(int token, Object cookie, int result) {

        }
    }


	/*
	 * (non-Javadoc)
	 * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
	 */
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(mAllPhotoView.isTakePhoto()){
    		mAllPhotoView.onActivityResult(requestCode, resultCode, data);
    	}else if(mFrontPhotoView.isTakePhoto()){
    		mFrontPhotoView.onActivityResult(requestCode, resultCode, data);
    	}else if(mTimePhotoView.isTakePhoto()){
    		mTimePhotoView.onActivityResult(requestCode, resultCode, data);
    	}
    }

    /**
	 * 更新project数据从数据库
	 * @param cursor 数据库数据
	 */
	private void updateProjectDataFromCursor(Cursor cursor){
		mProjectList = DatabaseUtil.getProjectDataList(cursor);
		if(mProjectList != null && mProjectList.size() > 0){
			for(ProjectDataItem item : mProjectList){
				updateViewFromProject(item);
			}
		}
		startQueryDataItemList();
	}

    /**
	 * 从project数据更新界面
	 */
	private void updateViewFromProject(ProjectDataItem item) {
		if (item.mId == 1) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_shape_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_1).setVisibility(View.GONE);
			}
		} else if (item.mId == 2) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_info_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_2).setVisibility(View.GONE);
			}
		} else if (item.mId == 3) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_baditems_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_3).setVisibility(View.GONE);
			}
		} else if (item.mId == 4) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_badfixeover_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_4).setVisibility(View.GONE);
			}
		} else if (item.mId == 5) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_baddate_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_5).setVisibility(View.GONE);
			}
		} else if (item.mId == 6) {
			if (item.isShow) {
				((TextView) findViewById(R.id.booth_connection_label)).setText(item.mName);
			} else {
				findViewById(R.id.booth_6).setVisibility(View.GONE);
			}
		}
	}

	/**
	 * 从管理员查询结果数据更新界面
	 */
	private void setDataFromAdminSearchData(){
		findViewById(R.id.svbottom_split_menu).setVisibility(View.GONE);
		findViewById(R.id.svbottom_menu_save).setVisibility(View.GONE);
		if(DataUtils.mQueryVisitContentResult.Data != null){
			mShapeChoiceView.setText(DataUtils.mQueryVisitContentResult.Data.BoothsShape);
			mShapeChoiceView.setEnabled(false);
	        mInfoChoiceView.setText(DataUtils.mQueryVisitContentResult.Data.BoothsLocation);
	        mInfoChoiceView.setEnabled(false);
	        mBadChoiceView.setText(DataUtils.mQueryVisitContentResult.Data.BoothsBreakageItem);
	        mBadChoiceView.setEnabled(false);
	        mConnectionChoiceView.setText(DataUtils.mQueryVisitContentResult.Data.WireExposed);
	        mConnectionChoiceView.setEnabled(false);
	        //图片数据
	        mAllPhotoView.setVisibility(View.GONE);
	        mFrontPhotoView.setVisibility(View.GONE);
	        mTimePhotoView.setVisibility(View.GONE);
	        String status = DataUtils.mQueryVisitContentResult.Data.BoothsBreakageStatus;
	        int complete = getBreakageStatusIndex(status);
	        //设置选中是否
	        if(complete != -1){
	        	if(complete == 1){
	        		mRadioGroup.check(mRadioGroup.getChildAt(0).getId());
	        	}else{
	        		mRadioGroup.check(mRadioGroup.getChildAt(1).getId());
	        	}
	        }
	        ViewsUtil.setRadioGroupdisable(mRadioGroup);
	        if(DataUtils.mQueryVisitContentResult.Data.BoothsBreakageDate != null){
	        	mDateView.setSavedData(DataUtils.mQueryVisitContentResult.Data.BoothsBreakageDate.getTime());
	        }
	        mDateView.setEnabled(false);
	        List<ProjectDataItem> list = DataUtils.getProjectDataList(StoresManagerSettings.DataProjectsColumns.PROJECT_TYPE_BOOTH);
			if(list != null && list.size() > 0){
				for(ProjectDataItem item : list){
					updateViewFromProject(item);
				}
			}
		}
	}

	/**
	 * 获取字符传对应view索引
	 * @param index 索引
	 */
	private int getBreakageStatusIndex(String status){
		if(getString(R.string.dialog_yes).equals(status)){
			return 1;
		}else if(getString(R.string.dialog_no).equals(status)){
			return 0;
		}
		return -1;
	}

	private DataChangeListener mDataChangeListener = new DataChangeListener(){
		@Override
		public void onDataChange(ChoiceView view) {
			// TODO Auto-generated method stub
			
		}
	};

	/**
     * 处理返回键
     */
    private boolean doBack(){
        if(isDataChange){
        	if(DataUtils.mUserData.isAdmin()){
        		return false;
        	}
            popExitDialog();
            return true;
        }
        return false;
    }

    /**
     * 按键事件处理
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode==KeyEvent.KEYCODE_BACK) { //返回
            if(!doBack()){
               finish();
            }
            return true;
        }
        return false;
    }

    /**
     * 退出提示
     * 
     */
    private void popExitDialog() {
    	Actions.popExitDialog(this);
    }
}
